﻿<?php
/**
* @version		$Id: view.html.php 9764 2007-12-30 07:48:11Z ircmaxell $
* @package		Joomla
* @subpackage	Poll
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view');
		
class amapViewsynthese_contratldb extends JView
{
	var $amap;
	function display($tpl = null)
	{
	$mainframe =& JFactory::getApplication();	
		if($this->amap->adLoggue)
		{
		
			$document =& JFactory::getDocument();
			$pathway  =& $mainframe->getPathway();

			// Adds parameter handling
			$params = $mainframe->getParams();

			$params->def( 'show_page_title', 1 );
			$params->def( 'page_title', 'adhésion');

			if ($this->amap->adLoggue){
				if ($this->amap->adExiste){
				

//recherche des contrats pour lequel  l'utilisateur connecté ( et non $idj ou $ida !) est personne relai
$user =& JFactory::getUser();
$userId = $user->get( 'id' );
$ida=$mainframe->getUserState('amap_ida');
//$query = "SELECT NomAbonnement FROM amap_abonnementadherent WHERE IDA=$ida ";
//echo $query;





/////////////////////////////////////////

        $sql="select relai1,relai2,relai3,relai4,relai5,relai6,relai7,relai8,relai9,relai10 from amap_adherent where amap_adherent.IDJ = $userId";
//echo $sql;
//$sql="SELECT distinct date,nomAbonnement from amap_jourdistributionabonnement inner join amap_abonnement on amap_jourdistributionabonnement.nomAbonnement=amap_abonnement.nom where date >curdate() and (amap_adherent.relai1=$userId or amap_adherent.relai2=$userId or amap_adherent.relai3=$userId or amap_adherent.relai4=$userId or amap_adherent.relai5=$userId";
$db =& JFactory::getDBO();
        $db->setQuery( $sql);
    $relais=$db->loadAssoc();

//var_dump( $relais);
//echo"<br>--------------<br>";
//echo"------------------------------------------<br>";
//var_dump($relais);

//echo "user $user  userId  $userId<br>";
//echo "relai1 ".$relais['relai1']."<br>";
//echo "relai2 ".$relais['relai2']."<br>";
//echo "relai3 ".$relais['relai3']."<br>";
//echo "relai4 ".$relais['relai4']."<br>";
//echo "relai5 ".$relais['relai5']."<br>";
if($relais['relai1']=="tous"){$sql="SELECT  Nom from amap_abonnement ";}
else
{
$sql="SELECT  Nom from amap_abonnement 
WHERE (Nom='".$relais['relai1']."' 
or Nom='".$relais['relai2']."' 
or Nom='".$relais['relai3']."' 
or Nom='".$relais['relai4']."' 
or Nom='".$relais['relai5']."'
or Nom='".$relais['relai6']."'
or Nom='".$relais['relai7']."'
or Nom='".$relais['relai8']."'
or Nom='".$relais['relai9']."'
or Nom='".$relais['relai10']."'


)";

//echo $sql;
}
/////////////////////////////////////////





//echo $query;
$database =& JFactory::getDBO();
$database->setQuery($sql);
$result=$database->loadRowList();
//var_dump($result);//$nomcontrat=$result[0][0];
//$societecontrat=$result[0][1];
//$produitcontrat=$result[0][2];

//echo"</FORM>";
echo '<h5>Choisir le contrat à synthétiser</h5>';

//http://test.amapluydebearn.org/index.php/component/amap/?view=adabo&abo=Juin%20a%20Novembre%202014%20:%20Lait-yaourts-Fromage%20blanc
echo "<FORM  ACTION='/index.php/component/amap/?view=liste_synthese_contrat' method='post'>";
//echo "<FORM ACTION='toto'>";

echo "<SELECT name='nomcontrat' value='$value[0]'  size='1'>";

foreach($result as $value)
{
echo "<OPTION   name='contrat' value='$value[0]' >$value[0]</OPTION>";
}
echo "</SELECT>";
echo "<INPUT TYPE='submit' value='valider la sélection'>";
$contrat=$_POST['nomcontrat'];
//echo "idaa $idaa nom contrat $contrat";
$contrat=$_POST['nomcontrat'];
echo "</FORM>";
echo "<div>Ce module permet de produire un document récapitulant les commandes validées pour un contrat pour tous les adhérents</div>";

				} 
				
				
			}
		}
parent::display($tpl);
	}
}
?>
